home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 146 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.3 KB

  1. Path: fido.asd.sgi.com!austern
  2. From: kuehl@uzwil.informatik.uni-konstanz.de (Dietmar Kuehl)
  3. Newsgroups: comp.std.c++
  4. Subject: Why is there no 'queue::top()'?
  5. Date: 26 Jan 1996 09:33:23 PST
  6. Organization: Fakultdt f|r Mathematik und Informatik
  7. Approved: austern@isolde.mti.sgi.com
  8. Message-ID: <3108ec17.0@news.uni-konstanz.de>
  9. Reply-To: dietmar.kuehl@uni-konstanz.de
  10. NNTP-Posting-Host: isolde.mti.sgi.com
  11. X-Original-Date: 26 Jan 96 14:58:31 GMT
  12. X-Newsreader: TIN [version 1.2 PL2]
  13. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  14.     iQBVAwUBMQkQfky4NqrwXLNJAQFXQAH+IjHJmmACFs2/TTnRMDPJYXt3eGFxZ0Gs
  15.     /bLgcMQPRWubdZmQXHXfVQUxxfvqqoogdqBTcl2/+W1Lbb/VT9fHIg==
  16.     =LfhT
  17. Originator: austern@isolde.mti.sgi.com
  18.  
  19. Hi,
  20.  
  21. The three standard classes 'stack', 'priority_queue', and 'queue' can
  22. be seen as classes which provide a sequence of the objects inserted
  23. into them depending on the order of insertation ('stack' and 'queue')
  24. and/or the elements themselves ('priority_queue'). In this respect it
  25. sometimes makes sense to define a template class or function which can
  26. take one of these three classes (or a similar one). However, these
  27. three classes have the function 'push()', 'pop()', 'empty(), and
  28. 'size()' in common (in addition to constructors and destructors).
  29. Unfortunately, this subset is normally not sufficient because there is
  30. no way to retrieve an "current" object. For 'stack' and
  31. 'priority_queue' a method 'top()' is defined to get the current object
  32. and for 'queue' methods 'front()' and 'back()' are defined.  To conform
  33. to the same requirements, it would be necessary for all three classes
  34. to share a common method (e.g. 'top()') to retrieve the current
  35. element. A suitable implementation of 'queue::top()' would be to return
  36. 'queue::front()' (this is what a queue normally defines as the current
  37. object).
  38.  
  39. Why is this 'queue::top() missing? Was it intentional? If so, what are
  40. the reasons and the suggested technic to work around the missing
  41. method?
  42. --
  43. dietmar.kuehl@uni-konstanz.de
  44. http://www.informatik.uni-konstanz.de/~kuehl
  45. I am a realistic optimist - that's why I appear to be slightly pessimistic
  46. ---
  47. [ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  48.   Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  49.   is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
  50.